#define _CRT_SECURE_NO_WARNINGS 
#include<iostream>
#include<cstring>
using namespace std;
const int N = 210, INF = 0x3f3f3f3f;
int dist[N][N];
int n, m, k;
void floyd()
{
    for (int k = 1; k <= n; k++)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    memset(dist, 0x3f, sizeof dist);
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++)
    {
        dist[i][i] = 0;
    }
    while (m--)
    {
        int x, y, z;
        cin >> x >> y >> z;
        dist[x][y] = min(dist[x][y], z);
    }
    floyd();
    while (k--)
    {
        int a, b;
        cin >> a >> b;
        if (dist[a][b] > INF / 2) cout << "impossible" << endl;
        else cout << dist[a][b] << endl;
    }
    return 0;
}